home *** CD-ROM | disk | FTP | other *** search
/ Windows 6-Pak - Disc 5 / Windows 6-Pak (InfoMagic) (Disc 5) (1999).ISO / C&C++Tools / BVCW95.ZIP / DOC.ZIP / CMATH.TXT < prev    next >
Encoding:
Text File  |  1998-02-04  |  38.6 KB  |  855 lines

  1.     CCCCCCC     MM         MM          A         TTTTTTTTTT    HH      HH
  2.   CC            MMM       MMM         AAA            TT        HH      HH
  3.  CCC            MMMM     MMMM        AA AA           TT        HH      HH
  4.  CCC            MM MM   MM MM       AA   AA          TT        HHHHHHHHHH
  5.  CCC            MM  MM MM  MM      AAAAAAAAA         TT        HH      HH
  6.   CC            MM   MMM   MM     AA       AA        TT        HH      HH
  7.     CCCCCCC     MM    M    MM    AA         AA       TT        HH      HH
  8.  
  9.  
  10.                            CMATH 1.4
  11.  
  12.                     Dr. Martin Sander Software Development
  13.                     Sertürnerstr. 11
  14.                     D-37085 Göttingen
  15.                     Germany
  16.                     e-mail: MartinSander@Bigfoot.com
  17.                     http://www.optivec.com
  18.  
  19. For the commercial version, please order by e-mail or through our web-site!
  20. See chapter 1.3 for details.
  21.  
  22. *****************************************************************************
  23.  
  24. !!     This is an ASCII text file!  It is best viewed with a simple        !!
  25. !!     DOS editor.                                                         !!
  26. !!     If you load this file into a word processor under Windows, you      !!
  27. !!     must use the filter "DOS text".                                     !!
  28. !!     Alternatively, you may use FCONVERT (shipped with Borland C++) to   !!
  29. !!     convert from ASCII (OEM) into the ANSI character set.               !!
  30. !!     preferably use the lettertype CourierNew 10 pt.                     !!
  31.  
  32.                  **************************************
  33.    German-speaking users:
  34.        Um die Kosten für das Herunterladen der Shareware-Version
  35.        über das Internet für alle so gering wie möglich zu halten,
  36.        enthält diese nur die englische Dokumentation. Sie finden
  37.        die deutsche Beschreibung separat unter
  38.                http://www.gwdg.de/~msander/Download/BC/CMDOCD.ZIP
  39.                  **************************************
  40.  
  41. OptiCode (TM) and OptiVec (TM) are trademarks of Dr. Martin Sander
  42. Software Dev.  Other brand and product names mentioned in this handbook
  43. for identification purposes are trademarks or registered trademarks of
  44. their respective holders.
  45.  
  46.  
  47. ****************************************************************************
  48. *                                                                          *
  49. *******                           Contents                           *******
  50. *                                                                          *
  51. ****************************************************************************
  52.  
  53. 1. Introduction
  54.    1.1 What is CMATH ?
  55.    1.2 Licence Terms
  56.    1.3 Registered Versions
  57.  
  58. 2. Getting Started
  59.    2.1 Installation
  60.    2.2 De-Installation
  61.  
  62. 3. Overview over the Functions of CMATH
  63.    3.1 Initialization of Complex Numbers
  64.    3.2 Data-Type Interconversions
  65.    3.3 Basic Complex Operations
  66.    3.4 Arithmetic Operations
  67.    3.5 Mathematical Functions
  68.  
  69. 4. Error Handling
  70.    4.1 General Error Handling of Complex Functions
  71.    4.2 Advanced Error Handling: Writing Messages into a File
  72.  
  73. 5. Syntax Reference
  74.    5.1 C++ Version
  75.    5.2 Plain-C Version
  76.  
  77. ****************************************************************************
  78. *                                                                          *
  79. *******                       1. Introduction                        *******
  80. *                                                                          *
  81. *****************************************************************************
  82.  
  83.  
  84. 1.1 What is CMATH ?
  85. -------------------
  86.  
  87. CMATH is a comprehensive library for complex-number arithmetis and
  88. mathematics. It is primarily intended as a high-quality replacement for
  89. the complex class libraries of popular C++ compilers. In addition,
  90. all functions may be called from C, without the necessity to use C++.
  91. Superior speed, accuracy and safety are achieved through the 
  92. implementation in Assembly language (as opposed to the compiled or 
  93. inline C++ code of the compilers' complex class libraries).
  94. Only for the most simple tasks, alternative inline C++ functions are used.
  95.  
  96. The implementation was guided by the following rules:
  97.  
  98.    1. Without any compromise, top priority is always given to the mathema-
  99.       tically correct result, with the accuracy demanded for the respective
  100.       data type. Especially for complex functions, this necessitates a
  101.       very thorough treatment of many different situations. To this end,
  102.       the various cases have to be distinguished with pedantic care.
  103.    2. Mathematical functions must be "safe" under all circumstances.
  104.       They may for no reason simply crash, but have to perform a decent
  105.       error treatment. This is true even - and perhaps especially - for
  106.       seemingly nonsense arguments, with the single exception of the
  107.       non-numbers INF and NAN, which occur themselves only as a result
  108.       of serious errors in other functions.
  109.    3. By all possible means, greatest execution speed must be attained.
  110.       (After all, you did not buy your fast computer for nothing!)
  111.    4. The program code has to be as compact as possible. However, in case
  112.       of conflicts, faster execution speed is always given priority
  113.       over smaller code size.
  114.  
  115. Having a look into the complex class libraries of popular compilers, you
  116. will immediately discover the differences between our approach and theirs.
  117. Often the mathematical functions are implemented by simply writing down the
  118. textbook formula. This yields relatively compact source code. But, due to
  119. round-off error of intermediate results, the final results returned by these
  120. functions are sometimes very inaccurate or even completely wrong. Moreover,
  121. they may lead to unhandled floating-point errors (this means: program crash!).
  122. Unnecessary to mention that the code thus generated is rather slow.
  123.  
  124. For programmers who prefer classis C-style functions over C++, CMATH
  125. provides all complex-number operations and functions also for the language C.
  126. This is accomplished through an additional set of alternative declarations
  127. of the complex types as structs in place of classes.
  128. Versions for Pascal and Fortran will be released soon, in which all
  129. functions shall have the same names as in the C version, as far as possible.
  130. The C++ classes and the C structs are binary compatible with each other.
  131. This point may become important for large projects with mixed C and C++
  132. modules.
  133.  
  134. Existing C++ code which uses the complex class library contained in
  135. <complex.h> can be left unchanged, because the CMATH functions and data
  136. types are also binary compatible with those of <complex.h>.
  137. Here is a detailed description of how to switch from the complex classes of
  138. Borland C++ to the new implementation given by CMATH:
  139.  
  140. *  In C++ modules, replace the statement
  141.        #include <complex.h>
  142.    by the statement
  143.        #include <newcplx.h>
  144.    Then, the following three complex classes are defined:
  145.    class complex<float>,  class complex<double>,
  146.    and  class complex<extended>.
  147.  
  148.    The data types fComplex, dComplex, and eComplex are defined as
  149.    synonyms for these classes.
  150.    In order to avoid the letter "L" (which is already over-used by "long int"
  151.    and "unsigned long" in the language C), the type "extended" is used here
  152.    as a synonym for "long double". Consequently, the complex data type
  153.    consisting of long doubles is named "eComplex". Thereby, the way is held
  154.    open for a future inclusion of whole-number complex types into CMATH.
  155.    Then,"liComplex" and "ulComplex" will denote the complex types consisting
  156.    of "long int" or "unsigned long" parts, respectively.
  157.  
  158. *  If you prefer to have the "classic" class complex of older releases
  159.    of Borland C++, you have to declare
  160.        #define CMATH_CLASSIC_COMPLEX
  161.    before (!) including <newcplx.h>.
  162.    In this case, only the class complex will be defined and gets the synonym
  163.    dComplex. Here you will have no access to the complex-number functions of
  164.    float and of extended precision.
  165.  
  166. *  For C modules, you cannot include <nexcplx.h>. Rather, please declare
  167.       #include <cmath.h>
  168.    If you are using only one level of floating-point precision, you may
  169.    wish to include only one of the type-specific include-files:
  170.    <cfmath.h>,  <cdmath.h>, or <cemath.h>, respectively.
  171.    The plain-C implementation of CMATH is based upon the following
  172.    definitions of the three complex data types:
  173.       typedef  struct { float     Re, Im; }  fComplex;
  174.       typedef  struct { double    Re, Im; }  dComplex;
  175.       typedef  struct { extended  Re, Im; }  eComplex;
  176.  
  177.    As described above, the data type "extended" is used as a synonym for
  178.    "long double", in order to avoid the letter "L".
  179.  
  180. *  In the C++ classes, the real and imaginary parts are declared as public
  181.    (in contrast to Borland C++ !) and named "Re" and "Im", respectively.
  182.    This allows to access them as "z.Re" and "z.Im"  in C++ modules as well
  183.    as in C modules.
  184.  
  185. This documentation describes the OptiVec implementations for
  186.  
  187. - Borland C++ (Version 3.0 or higher, incl. Borland C++ Builder)
  188.   for DOS and Microsoft Windows 3.0 or later (or Win-OS sessions under
  189.   IBM OS/2 2.0 or later; in the following, we will simply speak
  190.   of "Windows"). The library for the memory model FLAT for Windows95/98 and
  191.   WindowsNT requires Borland C++, version 4.0 or higher.
  192.  
  193. - Microsoft Visual C++ (Version 5.0 or higher)
  194.   for Windows95/98/NT on PC platforms.
  195.  
  196. - Powersoft Optima++ (Version 1.5 or higher)
  197.   for Windows95/98/NT on PC platforms.
  198.  
  199. Please note that only the documentation is valid for these different
  200. compilers. The libraries themselves are compiler-specific; each library
  201. can be used only with one compiler and, in the case of Borland C++,
  202. with one memory model.
  203.  
  204. Borland C++ only:
  205. -----------------
  206.    Depending on your choice when ordering or downloading the Shareware
  207.    version,
  208.    you have got either of the following three library versions:
  209.    memory model FLAT for Windows95/NT,
  210.                 LARGE for DOS, or
  211.                 LARGE for Windows 3.x.
  212.    All of them require, at least, a 386 computer equipped with a 387
  213.    coprocessor. This means: no emulation, no 486SX, but preferably 486DX,
  214.    Pentium or higher.
  215.  
  216.    The full (registered) version contains libraries for all memory models of
  217.    DOS, 16-bit Windows and 32-bit Windows. These libraries, in turn, are
  218.    shipped in three versions:
  219.    one for 486DX and Pentium computers, the second for 386 with 387,
  220.    the third for 286 with or without coprocessor, i.e. with emulation.
  221.  
  222. Microsoft Visual C++ only:
  223. --------------------------
  224.    The Shareware version is for "single-thread debug". The full (registered)
  225.    version for Microsoft Visual C++ contains additional libraries for "multi-
  226.    thread debug" and both single-thread and multi-thread release.
  227.  
  228.  
  229. Versions for other C compilers and for Pascal, Delphi, and Fortran are in
  230. preparation.
  231.  
  232.  
  233. 1.2 Licence Terms
  234. -----------------
  235.  
  236. This is the English Shareware version of CMATH ("SOFTWARE").
  237. It may be used under the following licence terms:
  238.  
  239. 1. You may test the SOFTWARE free of charge for an unlimited period of time.
  240.    This testing phase ends when you permanently integrate functions of this
  241.    SOFTWARE into any of your applications (programs, program parts...).
  242. 2. If you want to use this SOFTWARE for commercial purposes, you have
  243.    to purchase the registered version (see chapter 1.3).
  244. 3. Use of this SOFTWARE for educational purposes at schools and universities
  245.    remains free of charge. However, if any application created under these
  246.    terms is sold to others or otherwise used for commercial purposes,
  247.    paragraph 2 applies.
  248. 4. Distributing this SOFTWARE to others is allowed only in one of the
  249.    following two ways:
  250.    a) linked into your programs, so that the parts stemming from this
  251.       SOFTWARE do no longer appear as a library.
  252.    b) as a whole in unchanged form (in particular the Copyright and Licence
  253.       statements!), whereby you may ask a fee only and exclusively for the
  254.       physical act of copying the SOFTWARE.
  255. 5. This SOFTWARE is provided on an "as is" basis. Any explicit or implicit
  256.    warranties for the SOFTWARE are excluded.
  257.    Despite thorough testing of the SOFTWARE, errors and bugs cannot
  258.    be excluded with certainty. No claims as to merchantability or fitness
  259.    for a particular purpose are made.
  260.    You may not use the SOFTWARE in any environment or situation where
  261.    personal injury or excessive damage to anyone's property (including
  262.    your own) could arise from malfunctioning of the SOFTWARE.
  263.  
  264.  
  265. Copyright for the SOFTWARE and its documentation (C) 1996-1999 Martin Sander
  266.  
  267. All rights reserved, including those of translation into foreign languages.
  268.  
  269. Address of the author:
  270.               Dr. Martin Sander Software Development
  271.               Sertürnerstr. 11
  272.               D-37085 Göttingen
  273.               Germany
  274.               e-mail: MartinSander@Bigfoot.com
  275.  
  276.  
  277.  
  278. 1.3 Registered Versions
  279. -----------------------
  280.  
  281. In order to make this product affordable also for those who will not
  282. themselves make money using it, we offer an "educational edition" at a
  283. strongly reduced rate, in addition to the full "commercial edition".
  284. The contents of these two editions is identical. The only difference lies
  285. in the restrictions of use: The "educational edition" may not be used for
  286. commercial / business / government purposes, but is restricted to private
  287. and educational use.
  288.  
  289. Purchasing the full (registered) version gives you the right to use it on
  290. as many computers at a time as the number of units you bought.
  291. Corporate site and world-wide licences are available upon request.
  292.  
  293. The full version (both the commercial and the educational editions)
  294. of CMATH for Borland C++ and of CMATH for Microsoft Visual C++
  295.  
  296. -  support all memory models of Windows95/98, NT, 3.x, and DOS
  297.    (Borland C++)
  298.    or "single-thread", "multi-thread", "multi-thread DLL", both
  299.    debug and release  (Microsoft Visual C++)
  300.  
  301. -  (Borland C++ only: )
  302.    have individually optimized libraries for each degree of processor
  303.    backward-compatibility:
  304.       486DX/Pentium+ (optimized for Pentium/PentiumPro)
  305.       386+ (387 coprocessor required)
  306.       286+ (no coprocessor required).
  307.  
  308. -  come with printed documentation.
  309.  
  310. -  entitle you to two free updates.
  311.  
  312. -  can be ordered at the following conditions:
  313.  
  314.    a) if you can pay in German Marks (from 1999 on: in Euro)
  315.       and order directly from the author, the price is
  316.       DM  59,- for  1 unit of the educational edition
  317.       DM  99,- for  1 unit of the commercial edition,
  318.       DM 350,- for  5 units,
  319.       DM 600,- for 10 units    (incl. 16% VAT, plus DM 10,- handling charge).
  320.       Please order by sending an e-mail to MartinSander@bigfoot.com
  321.       or use a print-out of the file ORDER.TXT.
  322.       Payment options:
  323.           - pre-paid by DM Eurocheque
  324.           - C.O.D. (Cash-On-Delivery)
  325.           - upon invoice (only within Germany, net 14 days)
  326.  
  327.       If you have a European VAT ID, or if you order from outside the
  328.       European Union, you are exempt from the German VAT, but you may
  329.       have to pay your local VAT and/or import duties according to
  330.       local laws.
  331.  
  332.    b) International credit card or US-$ cheque payment is possible by
  333.       ordering through the following web-sites
  334.       (currently available only for CMATH for Borland C++):
  335.  
  336.       Atlantic Coast's SoftShop:
  337.       http://www.soft-shop.com/cgi-bin/order.html?136
  338.  
  339.           $ 39 for  1 unit of the educational edition
  340.           $ 60 for  1 unit of the commercial edition,
  341.           $200 for  5 units,
  342.           $350 for 10 units
  343.           Add $5 for shipping&handling and applicable VAT.
  344.  
  345.  
  346.       ShareIt:
  347.       http://www.shareit.com/programs/101353.htm
  348.  
  349.           $ 44 per unit of the educational edition (including S&H)
  350.           $ 65 per unit of the commercial edition (including S&H).
  351.                Add applicable VAT.
  352.  
  353.       Alternatively, send an e-mail to register@shareit.com
  354.       US customers may also order by calling 1-800-903-4152
  355.       (orders only please!). US check and cash orders can be sent to 
  356.       ShareIt!'s US office at
  357.            ShareIt! Inc.
  358.            P.O. Box 97841 
  359.            Pittsburgh, PA 15227-0241
  360.            USA
  361.       * Please note the program No.: 101353 when ordering through ShareIt! *
  362.  
  363.  
  364. ****************************************************************************
  365. *                                                                          *
  366. *******                 2. Getting Started                           *******
  367. *                                                                          *
  368. ****************************************************************************
  369.  
  370. 2.1 Installation
  371. ----------------
  372. If you got CMATH as a part of OptiVec (a comprehensive library of
  373. vectorized functions by the same author), CMATH is automatically installed
  374. when you install OptiVec itself. In this case, installation of CMATH is
  375. already included and you should skip this chapter to continue with chapter 3.
  376.  
  377. Otherwise, please note the following points:
  378.  
  379. 1.  In order to use CMATH, you need an already installed copy of your
  380.     C/C++ compiler. Install CMATH by executing INSTALL.EXE on the
  381.     installation disk.
  382.  
  383. 2.  Add the installation directory (which you chose during installation) to
  384.     the library search path and to the include-file search path of the IDE
  385.     and of the configuration file TURBOC.CFG, in case you are using the
  386.     command-line compiler of Borland C++.
  387.  
  388. 3.  Borland C++:
  389.       Choose the desired platform (DOS, Windows3.x, or Win32).
  390.       If you chose DOS or Windows3.x, select the memory model LARGE.
  391.       For Win32, it is automatically FLAT. Choose static linking.
  392.       You should also choose, at least, 386 code generation and real
  393.       coprocessor commands (i.e., no emulation).
  394.     Microsoft Visual C++:
  395.       Choose "single-thread debug".
  396.  
  397. 4.  Add the desired CMATH library to your project list.
  398.     Borland C++:
  399.         For DOS programs, this is the library CMATHL3.LIB,
  400.         for Windows3.x you need CMATHL3W.LIB,
  401.         for Win32, CMATHF3W.LIB.
  402.     Microsoft Visual C++:
  403.        The library needed is CMVCSD.LIB.
  404.  
  405. 5.  In your C++ programs, declare 
  406.          #include <newcplx.h>
  407.     For C modules, declare:
  408.          #include <cmath.h>
  409.     If you are using ObjectWindows or MFC, <newcplx.h> or <cmath.h>
  410.     must be included after(!) the include files for OWL or MFC.
  411.  
  412. 6. Borland C++, 16-bit programs only:
  413.     *   If the linker option "process extended dictionaries" is available
  414.         in your version of Borland C++, you must switch it on.
  415.         Otherwise, you might get a "Table limit exceeded" linker error.
  416.  
  417.     *   CMATH works with Borland (Turbo) C++, version 3.0 or higher. Since,
  418.         from version 4.0 on, Borland changed the name of the error handling
  419.         routine matherr (without underbar) into _matherr (with a leading
  420.         underbar), any 16-bit program using CMATH has to call a macro,
  421.         NEWMATHERR, which takes  care of redirecting calls to _matherr,
  422.         if necessary. You should place the call to NEWMATHERR into the
  423.         module containing  main() or OwlMain():
  424.  
  425.              #include .....
  426.              #include <nexcplx.h>   /* or: #include <cmath.h> */
  427.              NEWMATHERR
  428.  
  429.              int main( void )
  430.              {    ..........   }
  431.  
  432.         If you forget to call NEWMATHERR, you will get a linker error
  433.         "Unresolved external _matherr" in the Borland C versions from 4.0 on.
  434.  
  435.         Inclusion of the macro NEWMATHERR is not needed for 32-bit programs.
  436.  
  437. After these preparations, all CMATH functions are available for your programs.
  438.  
  439.  
  440. 2.2 De-Installation
  441. -------------------
  442.  
  443. Should you wish to remove CMATH from your computer after testing, please
  444. simply delete the directory CMATH with its subdirectories. The installation
  445. of CMATH does not affect any files outside its own directory, so there
  446. is nothing else to get rid of.
  447.  
  448.  
  449.  
  450. ****************************************************************************
  451. *                                                                          *
  452. *******       3. Overview over the Functions of CMATH                *******
  453. *                                                                          *
  454. ****************************************************************************
  455.  
  456. For C++, all functions of CMATH are declared in <nexcplx.h>.
  457. For C, there are the following three include-files:
  458. <cfmath.h> declares all functions for single precision (data type fComplex),
  459. <cdmath.h> contains all double-precision functions (data type dComplex), and
  460. <cemath.h> lists all functions for extended precision (data type eComplex).
  461. The include-file <cmath.h> unites the three include-files just mentioned.
  462.  
  463. In the following, it is often only the fComplex-version of a function that
  464. is explicitly mentioned. The versions for dComplex and eComplex are always
  465. exactly analogous.
  466.  
  467. All functions for the language C have a prefix denoting the data type on
  468. which the function works:
  469. "cf_" stands for single precision (arguments and return values of the data
  470.       type fComplex, sometimes together with float),
  471. "cd_" stands for double precision (dComplex and double), whereas
  472. "ce_" denotes extended-precision functions.
  473.  
  474. In C++, synonyms are defined for all these functions. The synonyms do not
  475. have a prefix, since the data type information is implicitly handled by the
  476. C++ compiler. The C++ function names are always identical to those found
  477. in the complex class libraries (if the respective function exists there).
  478. Of course, if you wish to use the C function names in your C++ modules,
  479. you can do so by including <cmath.h> instead of <newcplx.h>.
  480.  
  481.  
  482. 3.1 Initialization of Complex Numbers
  483. -------------------------------------
  484.  
  485. For C++ modules, there are several overloaded constructors:
  486.           fComplex fComplex( float RePart, float ImPart );
  487.           fComplex fComplex( float RePart );  // imaginary part always 0
  488.           fComplex fComplex( dComplex );
  489.           fComplex fComplex( eComplex );
  490.  
  491.           The interconversion between the complex types of different
  492.           level of accuracy may, in the course of down-conversions,
  493.           lead to OVERFLOW errors. These are are caught and treated
  494.           via _matherr.
  495.           Similarly to the constructor fComplex(), also dComplex() and
  496.           eComplex() exist in overloaded versions performing the same
  497.           tasks for the classes dComplex and eComplex, respectively.
  498.  
  499. Additionally, both in C++ and in plain-C modules, complex numbers may
  500. be initialized by separately assigning a value to the imaginary and
  501. real parts, e.g.:
  502.         z.Re = 3.0;   z.Im = 5.7;
  503.  
  504. Alternatively, in plain-C modules, the same initialization can be
  505. accomplished by the function fcplx:
  506.     z = fcplx( 3.0, 5.7 );
  507.  
  508. For double-precision complex numbers, use dcplx, for extended-precision
  509. complex numbers, use ecplx.
  510.  
  511. Since overloading of functions and constructors is specific to C++ and
  512. not available in plain C, the interconversions between the various
  513. complex types are performed via the functions
  514. cftocd,  cdtocf,  cftoce,  cetocf,  cdtoce,  and cetocd.
  515. As described above, OVERFLOW errors in the course of down-conversions
  516. are caught and treated via _matherr.
  517.  
  518. 3.2 Basic Complex Operations
  519. ----------------------------
  520.  
  521. The following basic complex operations are defined in CMATH:
  522.  
  523. C function  C++ synonym
  524. cf_conj     conj          complex-conjugate form,
  525. cf_neg      neg  (or -)   negation,
  526. cf_real     real          extraction of the real part,
  527. cf_imag     imag          extraction of the imaginary part,
  528. cf_polar    polar         conversion of polar coordinates into the "normal",
  529.                           Cartesian complex format
  530. cf_abs      abs           absolute value (magnitude of the pointer in the
  531.                           complex plane; this is treated as a math function
  532.                           with error handling),
  533. cf_arg      arg           argument (angle of the pointer in the complex
  534.                           plane),
  535. cf_norm     norm          norm (defined here as the square of the absolute
  536.                           value)
  537.  
  538. (The cd_ and ce_ versions are exactly analogous to the cf_ version)
  539.  
  540.  
  541. 3.3 Arithmetic Operations
  542. -------------------------
  543.  
  544. Only C++: The following set of operators is available for all of
  545.           the three complex classes:
  546.           +  -  *  /  +=  -=  *=  /=   ==   !=
  547.           These operators exist also for "mixed" arguments,
  548.           where one argument is complex, the other real and
  549.           where the arguments are of different floating-point
  550.           accuracies.
  551.  
  552. Since it is only the language C++, but not C, which allows to overload
  553. the arithmetic operators, all arithmetic operations of complex
  554. numbers are implemented in a different way for C modules. Here, we
  555. have the functions
  556.  
  557. cf_add        addition of two complex numbers
  558. cf_addRe      addition of a complex number and a real number
  559. cf_sub        subtraction of two complex numbers (first operand
  560.               minus the second operand)
  561. cf_subRe      subtraction of a real number from a complex number
  562. cf_subrRe     subtraction of a complex number from a real number
  563. cf_mul        multiplication of two complex numbers
  564. cf_mulRe      multiplication of a complex number and a real number
  565. cf_div        division of two complex numbers (first operand
  566.               divided by the second operand)
  567. cf_divRe      division of a complex number by a real number
  568. cf_divrRe     division of a real number by a complex number
  569.  
  570. (similarly the cd_ and ce_ versions)
  571.  
  572. The equality operator "=" is the only operator defined also in C for
  573. complex numbers.
  574.  
  575.  
  576. 3.4 Mathematical Functions
  577. --------------------------
  578.  
  579. CMATH contains all mathematical functions you would find in the complex
  580. class libraries, along with several additional ones:
  581.  
  582. C function   C++ synonym
  583. cf_abs       abs            ry = | zx |          absolute value
  584. cf_acos      acos           zy = acos( zx )      arcus cosine function
  585. cf_asin      asin           zy = asin( zx )      arcus sine function
  586. cf_atan      atan           zy = atan( zx )      arcus tangent function
  587. cf_cos       cos            zy = cos( zx )       cosine
  588. cf_cosh      cosh           zy = cosh( zx )      hyperbolic cosine
  589. cf_cubic     cubic          zy = zx**3           third power
  590. cf_exp       exp            zy = exp( zx )       exponential function
  591. cf_inv       inv            zy = 1.0 / zx        inverse
  592. cf_ipow      ipow           zy = zx**n           integer power
  593. cf_ln        ln             zy = ln( zx )        natural logarithm
  594. cf_log       log            zy = ln( zx )        identical to cf_ln, ln
  595. cf_log2      log2           zy = lb( zx )        binary logarithm
  596. cf_log10     log10          zy = lg( zx )        decadic logarithm
  597. cf_pow       pow            zy = zx**zexp        arbitrary power
  598. cf_powReBase pow, powReBase zy = r**zx           real base to complex power
  599. cf_powReExpo pow, powReExpo zy = zx**r           real power of complex base
  600. cf_quartic   quartic        zy = zx**4           fourth power
  601. cf_sin       sin            zy = sin( zx )       sine
  602. cf_sinh      sinh           zy = sinh( zx )      hyperbolic sine
  603. cf_square    square         zy = zx²             square
  604. cf_sqrt      sqrt           zy = sqrt( zx )      square root
  605. cf_tan       tan            zy = tan( zx )       tangent
  606. cf_tanh      tanh           zy = tanh( zx )      hyperbolic tangent
  607.  
  608. (similarly the cd_ and ce_ versions)
  609.  
  610.  
  611. ****************************************************************************
  612. *                                                                          *
  613. *******                      4. Error Handling                       *******
  614. *                                                                          *
  615. *****************************************************************************
  616.  
  617. 4.1 General Error Handling of Complex Functions
  618. -----------------------------------------------
  619.  
  620. The error handling of complex functions follows the rules employed also
  621. for real-number functions and operations. For all arithmetic operations,
  622. the design of the algorithms eliminates the danger of failure due to
  623. irregular intermediate results. Overflowing or otherwise irregular
  624. final results, however, will lead to a hardware interrupt being generated
  625. and, as a consequence, to a program abort.
  626.  
  627. In contrast to the arithmetic operations, all mathematical functions and
  628. all data-type interconversions perform a tight error checking and treat
  629. any detected error conditions via _matherr (for fComplex and dComplex
  630. functions) and _matherrl (for eComplex functions). All error messages
  631. eventually generated use the C name (and not the C++ synonym) of the
  632. failing function.
  633.  
  634. 16-bit programs only:
  635.    As mentioned already in chapter 2, Borland has changed the name of the
  636.    error-handling function "matherr" (without leading underbar), used in
  637.    the versions 3.x, into "_matherr" (with a leading underbar), from
  638.    version 4.0 on.
  639.    In order to make CMATH compatible with both the older and the later
  640.    versions of Borland C++, the following way of error handling was adopted:
  641.    In case of an error, all CMATH functions call primarily matherr (as in the
  642.    older versions of Borland C++). A macro NEWMATHERR provides for the
  643.    necessary redirection of these calls to _matherr, if a later version of
  644.    Borland C++ is used. Therefore, NEWMATHERR must be called once (!) in any
  645.    program using CMATH, after the inclusion of <cmath.h>. The best place
  646.    is the module containing the main(), WinMain(), or OWLMain() function:
  647.  
  648.        #include <cmath.h>
  649.        #include ...
  650.        NEWMATHERR
  651.          ......
  652.        main()
  653.        { ... }
  654.  
  655.  
  656. If you use CMATH as a part of OptiVec, consult also chapter 5 of
  657. HANDBOOK.TXT for further information on floating-point error handling.
  658. If you use CMATH separately from OptiVec, you should at least know
  659. about some advanced error handling features, borrowed from VectorLib and
  660. described in the following chapter.
  661.  
  662.  
  663. 4.2 Advanced Error Handling: Writing Messages into a File
  664. ---------------------------------------------------------
  665.  
  666. ANSI C provides the user-definable function perror to print error messages.
  667. However, several compilers, including Borland C++, do not use perror for
  668. this purpose. This means that the way error messages are printed is not
  669. controllable by the programmer. While this is fine in most instances, there
  670. may be situations in which you might, for example, wish the error messages
  671. not to be printed to the screen, but rather into a file, so that you could
  672. check later what has gone wrong. If you use Borland C++ for Windows, an
  673. additional motivation could come from the fact that, for any error, a
  674. message box is displayed and program execution interrupted until you
  675. acknowledge having taken notice of the error.
  676.  
  677. You might wish to circumvent this. To this end, CMATH borrows from OptiVec
  678. the function  V_setErrorEventFile. This function needs as arguments the
  679. desired name of your event file and a switch named ScreenAndFile which
  680. decides if the error message is printed only into the file, or additionally
  681. to the screen as well.
  682. Example:     V_setErrorEventFile( "MyErrors.LOG", 1 );
  683.  
  684. Note that this redirection of error messages is valid only for errors
  685. occurring in CMATH (and, of course, VectorLib) routines. If you care to
  686. do so, however, there is a way to extend the redirection also to
  687. "non-CMATH/VectorLib" functions:  you may modify  _matherr and _matherrl
  688. so that the statement
  689.     return 0;
  690. (which signals an unresolved error)  is replaced by the sequence
  691.     V_noteError( e->name, e->type ); return 1;
  692.  
  693. Thereby the task of printing the error message for unresolved errors is
  694. passed to V_noteError. Keep in mind that it is the return value of _matherr
  695. which decides if an error message is printed by the default error handler
  696. of Borland C/C++. Thus, after the call to V_noteError, the printing of the
  697. default error messages is by-passed by returning "1". (Also, do not forget
  698. that it is your(!) _matherr routine which determines which errors you accept
  699. and which not.)
  700.  
  701. For example, your _matherr function (matherr - without the leading underbar
  702. - for Borland C++ 3.0 and 3.1) might look like the following one:
  703.  
  704.     #include <math.h>
  705.     int  _matherr( struct exception *e)
  706.     {
  707.         if( (e->type == UNDERFLOW) ││ (e->type == TLOSS) )  /* ignore */ ;
  708.         else   /* all other errors deserve at least notice */
  709.         {
  710.               V_noteError( e->name, e->type );
  711.               if (e->type == DOMAIN) exit(1); /* really fatal */
  712.         }
  713.         return 1;
  714.     }
  715.  
  716. (Of course, if you decide to change _matherr, do not forget to change
  717. _matherrl in the same way!).
  718.  
  719. The default printing of error messages on the screen alone is restored by
  720. V_closeErrorEventFile().
  721.  
  722.  
  723. ****************************************************************************
  724. *                                                                          *
  725. *******               5. Syntax Reference                            *******
  726. *                                                                          *
  727. ****************************************************************************
  728.  
  729. In the following, the syntax of all CMATH functions of float / fComplex
  730. accuracy is given. The syntax of the functions for double and extended
  731. precisions is exactly analogous.
  732. If you chose the "classic" class complex, this is also similar.
  733. Just replace "float" by "double" and "fComplex" by "complex".
  734. (Of course, the type-casting operators and the interconversion functions
  735. do not exist if there is only one type.)
  736.  
  737. 5.1 C++ Version
  738. ---------------
  739. At this place, the syntax is given in a simplified form (just what you need
  740. to know in order to use these functions). For details of the declaration,
  741. see the class complex<float> in <nexcplx.h>.
  742. The arithmetic operators are not listed; their use is identical to the use
  743. of the real-number operators; suffice it to say they are all available.
  744.  
  745.     float     abs( fComplex _z );
  746.     fComplex  acos( fComplex _z );
  747.     float     arg( fComplex _z );
  748.     fComplex  asin( fComplex _z );
  749.     fComplex  atan( fComplex _z );
  750.     fComplex  cdtocf( dComplex cd );
  751.     fComplex  cetocf( eComplex ce );
  752.     fComplex  conj( fComplex _z );
  753.     fComplex  cos( fComplex _z );
  754.     fComplex  cosh( fComplex _z );
  755.     fComplex  cubic( fComplex _z ); 
  756.     fComplex  exp( fComplex _z );
  757.     fComplex  fComplex( float Re_part, float Im_part );
  758.     fComplex  fComplex( float Re_part );  // constructors
  759.     fComplex  fComplex( dComplex cd );
  760.     fComplex  fComplex( eComplex ce );   // type-casting constructors
  761.     float     imag();   // to be used as   zim = z.imag();
  762.     float     imag( fComplex _z );
  763.     fComplex  inv( fComplex _z );   
  764.     fComplex  ipow( fComplex __base, int __expon ); 
  765.     fComplex  ln( fComplex _z );
  766.     fComplex  log( fComplex _z ); 
  767.     fComplex  log2( fComplex _z );
  768.     fComplex  log10( fComplex _z );
  769.     fComplex  neg( fComplex _z );
  770.     float     norm( fComplex _z );
  771.     fComplex  polar( float _mag, float _angle=0 );
  772.     fComplex  pow( fComplex __base, float __expon );
  773.     fComplex  powReExpo( fComplex __base, float __expon );
  774.     fComplex  pow( float __base, fComplex __expon);
  775.     fComplex  powReBase( float __base, fComplex __expon );
  776.     fComplex  pow( fComplex __base, fComplex __expon);
  777.     fComplex  quartic( fComplex _z ); 
  778.     float     z.real();     // to be used as    zre = z.real();
  779.     float     real( fComplex _z );
  780.     fComplex  sin( fComplex _z );
  781.     fComplex  sinh( fComplex _z );
  782.     fComplex  sqrt( fComplex _z );
  783.     fComplex  square( fComplex _z );
  784.     fComplex  tan( fComplex _z );
  785.     fComplex  tanh( fComplex _z );
  786.     
  787.  
  788. 5.2 Syntax Reference for the Plain-C Version.
  789. Again, the syntax is given in a simplified form here. For details of
  790. the declaration, see <cfmath.h>.
  791. The prefix cf_ denotes the accuracy level "float / fComplex".
  792. For the functions of double/dComplex and extended/eComplex precisions,
  793. the prefixes are cd_ and ce_, respectively.
  794. Since overloaded operators are specific to C++, only the operator "="
  795. exists for plain C.
  796.  
  797.     float     cf_abs(  fComplex __z );
  798.     fComplex  cf_acos( fComplex __z );
  799.     fComplex  cf_add(   fComplex __x, fComplex __y );
  800.     fComplex  cf_addRe( fComplex __x, float __yRe );
  801.     float     cf_arg(  fComplex __z );
  802.     fComplex  cf_asin( fComplex __z );
  803.     fComplex  cf_atan( fComplex __z );
  804.     fComplex     cdtocf( dComplex __zd );
  805.     fComplex     cetocf( eComplex __ze );
  806.     fComplex  cf_conj( fComplex __z );
  807.     fComplex  cf_cos(  fComplex __z );
  808.     fComplex  cf_cosh( fComplex __z );
  809.     fComplex  cf_cubic( fComplex __z );
  810.     fComplex  cf_div(   fComplex __x, fComplex __y );
  811.     fComplex  cf_divRe( fComplex __x, float __yRe );   /*  x / yRe  */
  812.     fComplex  cf_divrRe( fComplex __x, float __yRe );  /*  yRe / x  */
  813.     fComplex  cf_exp(  fComplex __z );
  814.     fComplex  fcplx( float __ReVal, float __ImVal);
  815.     float     cf_imag( fComplex z );
  816.     fComplex  cf_inv(  fComplex __z );    /*   1.0 / z   */
  817.     fComplex  cf_ipow( fComplex __z, int __exponent );
  818.     fComplex  cf_ln(    fComplex __z );
  819.     fComplex  cf_log(   fComplex __z ); 
  820.     fComplex  cf_log2(  fComplex __z );
  821.     fComplex  cf_log10( fComplex __z );
  822.     fComplex  cf_mul(   fComplex __x, fComplex __y );
  823.     fComplex  cf_mulRe( fComplex __x, float __yRe );
  824.     fComplex  cf_neg(  fComplex __z );
  825.     float     cf_norm( fComplex __z );
  826.     fComplex  cf_polar( float __mag, float __angle );
  827.     fComplex  cf_pow( fComplex __base, fComplex __exponent );
  828.     fComplex  cf_powReBase( float __base, fComplex __exponent ); 
  829.     fComplex  cf_powReExpo( fComplex __base, float __exponent );
  830.     fComplex  cf_quartic( fComplex __z );  
  831.     float     cf_real( fComplex z );
  832.     fComplex  cf_sin(  fComplex __z );
  833.     fComplex  cf_sinh( fComplex __z );
  834.     fComplex  cf_square( fComplex __z );
  835.     fComplex  cf_sqrt( fComplex __z );
  836.     fComplex  cf_sub(   fComplex __x, fComplex __y );
  837.     fComplex  cf_subRe( fComplex __x, float __yRe );  /* x - yRe */
  838.     fComplex  cf_subrRe( fComplex __x, float __yRe ); /* yRe - x */
  839.     fComplex  cf_tan(  fComplex __z );
  840.     fComplex  cf_tanh( fComplex __z );
  841.  
  842.  
  843. *****************************************************************************
  844.  
  845. Although CMATH underwent thorough testing, there is always a possibility
  846. that a problem might have escaped our attention. Should you feel you dis-
  847. covered a "bug", please kindly try to specify the conditions under which
  848. you observed the problem as exactly as possible. Please let the author
  849. know what you have found!
  850. e-mail:  MartinSander@Bigfoot.com
  851.  
  852. Copyright (C) Martin Sander 1996-1999
  853.  
  854. *****************************************************************************
  855.